package IMIC.NGUYENVANDOAN.XML_DEMO;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

public class MODULE01_B03 extends JFrame {

    private JPanel contentPane;
    private JTextField txtInputs;
    private JTextField txtOutput;
    
    //1. Khai báo 1 List Objets trong Java 
    private List<Student> lisStudent = null;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MODULE01_B03 frame = new MODULE01_B03();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public MODULE01_B03() {
        //2. Khởi tạo đối tượng danh sách sinh viên
        lisStudent  =new ArrayList<Student>();
        
        
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 264);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        
        txtInputs = new JTextField();
        txtInputs.setBackground(Color.ORANGE);
        txtInputs.setFont(new Font("Cambria", Font.PLAIN, 25));
        txtInputs.setBounds(10, 11, 414, 78);
        contentPane.add(txtInputs);
        txtInputs.setColumns(10);
        
        txtOutput = new JTextField();
        txtOutput.setBackground(SystemColor.textHighlight);
        txtOutput.setFont(new Font("Cambria", Font.PLAIN, 25));
        txtOutput.setColumns(10);
        txtOutput.setBounds(10, 148, 414, 67);
        contentPane.add(txtOutput);
        
        JButton btnNewButton = new JButton("THÊM SINH VIÊN VÀO DANH SÁCH");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(lisStudent == null){
                    lisStudent  =new ArrayList<Student>();
                }
                else{
                    Student obj = new Student();
                    obj.setFullName(txtInputs.getText());
                    lisStudent.add(obj);
                    txtOutput.setText("Hiện có: "+ lisStudent.size() +
                                " sinh viên trong danh sách!");
                }
            }
        });
        btnNewButton.setFont(new Font("Cambria", Font.PLAIN, 18));
        btnNewButton.setBounds(52, 100, 321, 37);
        contentPane.add(btnNewButton);
    }
}
